package com.exam.service.impl;

import com.exam.mapper.TeacherMapper;
import com.exam.po.Announcement;
import com.exam.po.Teacher;
import com.exam.service.TeacherService;
import com.exam.ustudent.UStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author mahaoqi
 * @ClassName TeacherServiceImpl
 * @Description TODO
 * @Date 2021/1/11 18:49
 * @Version 1.0
 **/
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherMapper teacherMapper;
    @Override
    public List<UStudent> findStudentByCourse(Integer teacherId, Integer page, Integer size) {
        return teacherMapper.findStudentsByCourse(teacherId, (page - 1) * size, size);
    }

    @Override
    public int findCountStudents(Integer teacherId) {
        return teacherMapper.findStudentByTeacherCounts(teacherId);
    }

    /*
     * @Author mahaoqi
     * @Description 添加教师
     * @Date 2021/1/11 19:03
     * @Param [teacher]
     * @return boolean
     **/
    @Override
    public boolean addTeacher(Teacher teacher) {
        return teacherMapper.insertSelective(teacher)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 根据id删除教师
     * @Date 2021/1/11 19:06
     * @Param [tid]
     * @return boolean
     **/
    @Override
    public boolean removeTeacher(Integer teacherid) {
        return teacherMapper.deleteByPrimaryKey(teacherid)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 修改教师信息
     * @Date 2021/1/11 19:12
     * @Param [teacher]
     * @return java.lang.Boolean
     **/
    @Override
    public boolean modifyTeacher(Teacher teacher) {
        return teacherMapper.updateByPrimaryKeySelective(teacher)>0;
    }

    /*
     * @Author mahaoqi
     * @Description 分页查询
     * @Date 2021/1/11 19:23
     * @Param [page, pageSize]
     * @return java.util.List<com.exam.po.Teacher>
     **/
    @Override
    public List<Teacher> findList(Integer page, Integer pageSize) {
        return teacherMapper.selectList((page-1)*pageSize,pageSize);
    }

    /*
     * @Author mahaoqi
     * @Description 查找记录
     * @Date 2021/1/11 19:45
     * @Param []
     * @return int
     **/
    @Override
    public int findCount() {
        return teacherMapper.selectCount();
    }

    @Override
    public List<Announcement> findAnnouncements() {
        return teacherMapper.selectAllAnnouncement();
    }
}
